<template>
    <div class="activity">
        <!-- search -->
        <div class="search">
            <input class="searchInput" @focus="inputFocus" @blur="inputBlur" v-model="searchInput">
            <i class="search-icon" v-show="searchShow"></i>
            <span class="searchPlaceHolder" v-show="searchShow">搜索</span>
        </div>
        <mTitle :title="title"></mTitle>
        <!-- <div class="check-title" @click="handleMskShow">
            <span class="check-text">{{checkValue}}</span>
            <span class="check-icon iconfont">&#xe615;</span>
        </div> -->
        <scroll class="activity-container" :data="activityList" v-show="!searchInput">
            <div>
                <ul class="activity-item">
                    <router-link :to="'activityPastText/'+item.id" tag="li" class="activity-list" v-for="(item, index) in activityList" :key="index">
                        <div class="left">
                            <img class="img" v-lazy="item.coverimg" alt="" />
                        </div>
                        <div class="middle">
                            <div class="activity-list-title">{{item.title}}</div>
                            <div class="start-wrapper">
                                <div class="start-text">
                                    <i class="icon"></i>
                                    <span class="text">开始时间</span>
                                </div>
                                <div class="start-time">
                                    <span class="start-date">{{item.startdate}}</span>
                                    <span class="start-hour">{{item.starttime}}</span>
                                </div>
                                <div class="end-text">
                                    <i class="icon"></i>
                                    <span class="text">结束时间</span>
                                </div>
                                <div class="end-time">
                                    <span class="end-date">{{item.enddate}}</span>
                                    <span class="end-hour">{{item.endtime}}</span>
                                </div>
                            </div>
                        </div>
                    </router-link>
                </ul>
            </div>
            <!-- 请求数据loading -->
            <div class="loading-wrapper" v-show="!activityList.length">
                <loading></loading>
            </div>
        </scroll>
        <!-- 匹配搜索结果 -->
        <scroll class="activity-container" :data="activityList" v-show="list.length">
            <div>
                <ul class="activity-item">
                    <router-link :to="'activityPastText/'+item.id" tag="li" class="activity-list" v-for="(item, index) in list" :key="index">
                        <div class="left">
                            <img class="img" :src="item.coverimg" alt="" />
                        </div>
                        <div class="middle">
                            <div class="activity-list-title">{{item.title}}</div>
                            <div class="start-wrapper">
                                <div class="start-text">
                                    <i class="icon"></i>
                                    <span class="text">开始时间</span>
                                </div>
                                <div class="start-time">
                                    <span class="start-date">{{item.startdate}}</span>
                                    <span class="start-hour">{{item.starttime}}</span>
                                </div>
                                <div class="end-text">
                                    <i class="icon"></i>
                                    <span class="text">结束时间</span>
                                </div>
                                <div class="end-time">
                                    <span class="end-date">{{item.enddate}}</span>
                                    <span class="end-hour">{{item.endtime}}</span>
                                </div>
                            </div>
                        </div>
                    </router-link>
                </ul>
            </div>
        </scroll>
        <div class="no-result" v-show="!list.length && searchInput">暂无搜索结果</div>
        <div class="activity-fixed">
            <div class="activity-fixed-item" v-for="(item,index) in activityActive" :key="index" :class="{active:index===1}" @click="checkActivity(index)">{{item}}</div>
        </div>
        <van-actionsheet v-model="mskShow" :actions="actions" cancel-text="取消" />
    </div>
</template>

<script>
    import axios from 'axios'
    import mTitle from 'base/title/title'
    import Scroll from 'base/scroll/scroll'
    import Loading from 'base/loading/loading'

    export default {
        data () {
            return {
                searchInput: "",
                searchShow: true,
                title: "往期活动",
                checkValue: "全部",
                activityList: [],
                activityActive: ['即将开始','往期活动'],
                insActive: 0,
                mskShow: false,
                list: [],
                DetailList: {},
                actions: [
                    {
                        name: '全部',
                        callback: this.handleClick
                    },
                    {
                        name: '演出',
                        callback: this.handleClick
                    },
                    {
                        name: '展览',
                        callback: this.handleClick
                    },
                    {
                        name: '赛事',
                        callback: this.handleClick
                    },
                    {
                        name: '讲座',
                        callback: this.handleClick
                    }
                ]
            }
        },
        methods: {
            inputFocus () {
                this.searchShow = false
            },
            inputBlur () {
                if (this.searchInput === "") {
                    this.searchShow = true
                }
            },
            handleMskShow () {
                this.mskShow = !this.mskShow
            },
            handleClick(item) {
                this.checkValue = item.name
                this.mskShow = false
            },
            checkActivity (index) {
                if (index === 0) {
                    this.$router.replace({path: '/activity'})
                }
            },
            getActivityInfo () {
                axios.post('/api/index.php?g=Api&m=Ucenter&a=activelist', {
                    openid: localStorage.getItem("openid"),
                    mid: localStorage.getItem("memberid"),
                    acttype: 2
                }).then((res) => {
                    if (res.data.rescode=='0000') {
                        this.activityList = res.data.data
                    }
                }).catch(function (error) {

                })
            }
        },
        watch: {
            searchInput () {
                this.list = []
                let result = []
                if(this.searchInput === "") {
                    result = []
                    this.list = []
                    return
                }
                for (let i in this.activityList) {
                    let value = this.activityList[i].title
                    if (value.indexOf(this.searchInput) > -1) {
                        result.push(i)
                    }
                }
                for(let k in result) {
                    this.list = this.list.concat(this.activityList[result[k]])
                }
            }
        },
        components: {mTitle,Scroll,Loading},
        created () {
            this.getActivityInfo()
        }
    }
</script>

<style lang="stylus" scoped>
    @import '~common/stylus/mixins.styl'
    
    .activity
        width: 100%
        height: 100%
        position: relative
        overflow: hidden
        .search
            width: 100%
            height: 44px
            background: #efeff4
            padding: 0 15px
            box-sizing: border-box
            -webkit-box-sizing: border-box
            position: relative
            overflow: hidden
            .searchInput
                width: 100%
                height: 32px
                background: #fff
                margin-top: 6px
                border: none
                border-radius: 0
                padding: 0 10px
                box-sizing: border-box
                -webkit-box-sizing: border-box
            .search-icon
                position: absolute
                background: url('./search-icon.png') no-repeat
                width: 13px
                height: 13px
                background-size: 100% 100%
                top: 16px
                left: 50%
                margin-left: -15px
            .searchPlaceHolder
                font-size: 14px
                color: #979797
                position: absolute
                top: 17px
                left: 51%
        .check-title
            position: absolute
            top: 58px
            right: 15px
            color: #fff
        .no-result
            padding: 0 15px
            line-height: 30px
            font-size: 16px
            color: #888
        .activity-fixed
            position: fixed
            bottom: 0
            height: 40px
            display: flex
            width: 100%
            line-height: 40px
            border-top: 1px solid #eee
            box-sizing: border-box
            .activity-fixed-item
                flex: 1
                text-align: center
                color: #000
                background: #fff
                &.active
                    background: #0094d4
                    color: #fff
        .activity-container
            position: absolute
            top: 86px
            bottom: 40px
            width: 100%
            padding: 0 15px
            box-sizing: border-box
            overflow: hidden
            .loading-wrapper
                position: absolute
                width: 100%
                top: 50%
                -webkit-transform: translateY(-50%)
                transform: translateY(-50%)
                z-index: 9
            .activity-item
                width: 100%
                .activity-list
                    width: 100%
                    height: 120px
                    border-bottom: 1px solid #eee
                    box-sizing: border-box
                    display: flex
                    align-items: center
                    overflow: hidden
                    position: relative
                    .left
                        flex: 0 0 100px
                        width: 100px
                        margin-right: 10px
                        .img
                            width: 100px
                    .middle
                        flex: 1
                        ellipsis()
                        .activity-list-title
                            width: 100%
                            font-size: 14px
                            ellipsis()
                        .start-wrapper
                            margin-top: 6px
                            .start-text,.end-text
                                font-size: 0
                                .icon
                                    background: url('./icon1.png') no-repeat
                                    width: 9px
                                    height: 9px
                                    background-size: 100% 100%
                                    display: inline-block
                                .text
                                    font-size: 14px
                                    color: #0094d4
                                    display: inline-block
                                    margin-left: 6px
                            .start-time,.end-time
                                font-size: 0
                                margin-top: 4px
                                .start-date,.end-date
                                    font-size: 14px
                                    color: #d40000
                                .start-hour,.end-hour
                                    font-size: 14px
                                    color: #d40000
                                    margin-left: 10px
                            .end-text
                                margin-top: 4px
                                .icon
                                    background: url('./icon2.png') no-repeat
                                    background-size: 100% 100%
                                .text
                                    color: #888
                            .end-time
                                .end-date,.end-hour
                                    color: #888
                    .right
                        position: absolute
                        right: 0
                        top: 43px
                        .btn
                            width: 66px
                            height: 24px
                            background: #0094d4
                            border-radius: 20px
                            color: #fff
                            display: block
                            text-align: center
                            line-height: 24px
                            font-size: 14px
                            &.success
                                background: #0094d4          
</style>